import { v4 as uuid } from 'uuid';
import insert from '@feidao/web/atom/nodejs/db/insert';
import log from '@feidao/web/atom/nodejs/logger/log';
import sys_date from '@feidao/web/atom/nodejs/msg/sys-date';
import { systemid } from './config';

interface Message {
}


export default async function atom(msg: Message, action_id: string, session_id: string, spaceid: string) {
	log('服务开始');
	// 获取系统时间
	const date_info: any = await sys_date(action_id, session_id, spaceid);

	const { prepare, exec } = insert(action_id, session_id, spaceid, systemid);
	prepare('atom_01', [{ _id: uuid(), a: 100, b: '100', c: 100.2, d: true, e: date_info.timeStamp, f: date_info, g: null }]);

	const s_res = await exec();

	prepare('atom_02', [{ _id: uuid(), a: 200 }]);

	const s_res2 = await exec();
	log('同一个systemid下的表可以操作多张表');

	log('两种执行方式');
	// const res = await exec();

	log('无论成功失败都要有返回值');

	log('mongodb的数据新增');
	log('关系型数据库新增表数据，表明，列名，字段类型，长度限制');
	if (s_res.code === 1 && s_res2.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}
}
